package com.jqq.writer;

import java.io.FileWriter;
import java.io.IOException;

/**
 * @author 姬倩倩
 * @version 1.0
 */
public class FileWriter_ {
    public static void main(String[] args) {
        String filePath = "d:\\hello.txt";
        //创建FileWriter对象
        FileWriter fileWriter = null;

        try {
            char[] chars = {'a', 'b', 'c'};
            fileWriter = new FileWriter(filePath, true);
            //writer(int)：写入单个字符
            fileWriter.write('H');
            //writer(char[])：写入指定数组
            fileWriter.write(chars);
            //writer(char[], off, len)：写入指定数组的指定部分
            fileWriter.write("edf".toCharArray(), 0, 3);
            //writer(string)：写入整个字符串
            fileWriter.write("你好，上海！");
            //writer(string, off, len)：写入字符串的指定部分
            fileWriter.write("苏州南京", 0, 2);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileWriter != null) {
                try {
                    fileWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println("程序结束..");
    }
}
